var longestPalindrome = function(s) {
    if (s.length < 2) return s;
    let start = 0, maxLen = 1;

    // 辅助函数：以 left/right 为中心扩展
    function expandAroundCenter(left, right) {
        while (left >= 0 && right < s.length && s[left] === s[right]) {
            if (right - left + 1 > maxLen) {
                start = left;
                maxLen = right - left + 1;
            } //记录最长的回文子串
            left--;
            right++;
        }
    }

    for (let i = 0; i < s.length; i++) {
        expandAroundCenter(i, i);     // 奇数回文中心
        expandAroundCenter(i, i + 1); // 偶数回文中心
    }

    return s.slice(start, start + maxLen);
};
console.log(longestPalindrome("babad"));

longestPalindrome("babad"); // "bab" 或 "aba"
longestPalindrome("cbbd");  // "bb"
